package com.wx.domain.handler.subject;

import com.wx.subject.common.enums.SubjectInfoTypeEnum;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: xx-club
 * @BelongsPackage: com.wx.domain.handler.subject
 * @Author: wangx
 * @CreateTime: 2024-03-14  11:10
 * @Description:
 * @Version: 1.0
 */
@Component
public class SubjectTypeHandlerFactory implements InitializingBean {

    @Resource
    private List<SubjectTypeHandler> subjectTypeHandlerList;
    private Map<SubjectInfoTypeEnum,SubjectTypeHandler> subjectTypeHandlerMap = new HashMap<>();

    public SubjectTypeHandler getSubjectTypeHandler(int  type){
        SubjectInfoTypeEnum typeEnum = SubjectInfoTypeEnum.getByCode(type);
        return subjectTypeHandlerMap.get(typeEnum);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        subjectTypeHandlerList.forEach(handler -> subjectTypeHandlerMap.put(handler.getType(),handler));
        // 初始化的时候，将所有的处理器进行注册
        // 注册到map中

    }
}


